package neu.soft.controller;

import neu.soft.entity.DO.City;
import neu.soft.entity.DO.Province;
import neu.soft.exception.AppException;
import neu.soft.exception.AppExceptionCodeMsg;
import neu.soft.service.RegionService;
import neu.soft.vo.ResultBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;
import java.util.Map;


/**
 * @author 李博
 * 查询省份城市等位置信息，统一用Province返回给前端
 */
@RestController
@RequestMapping("/province")
@CrossOrigin
public class ProvinceController {

    @Autowired
    RegionService regionService;

    @GetMapping
    public ResultBean<List<Province>> getLoc(){
        List<Province> provinces = regionService.findLocInfo();
        return ResultBean.success("查询成功",provinces);
    }

    @PostMapping("/getInfo")
    public ResultBean<City> getInfo(@RequestBody Map<String,Object> map){
        if (map==null){
            throw new AppException(AppExceptionCodeMsg.REQUEST_PARAM_EMPTY);
        }
        City city = regionService.findInfo(map);
        return ResultBean.success(city);
    }
}
